﻿function __dialog()
{
	this.masker=null;
	this.box=null;
	this.title=null;
	this.iframe=null;
	this.html=null;
	this.StyleSheet=null;
	this.btnclose=null;

}

__dialog.prototype.open=function(option)
{

	if(this.masker)
	{
		this.masker=window.parent.document.getElementById("dialog_masker");
	}
	else
	{
		this.masker=window.parent.document.createElement("div");
		this.masker.id="dialog_masker"
	}
	if(this.box)
	{
		this.box=window.parent.document.getElementById("dialog_box");
	}
	else
	{
		this.box=window.parent.document.createElement("div");
		this.box.id="dialog_box"
	}
	if(this.title)
	{
		this.title=window.parent.document.getElementById("dialog_title");
	}
	else
	{
		this.title=window.parent.document.createElement("div");
		this.title.id="dialog_title"
	}
	if(this.btnclose)
	{
		this.btnclose=window.parent.document.getElementById("dialog_btnclose");
	}
	else
	{
		this.btnclose=window.parent.document.createElement("a");
		this.btnclose.id="dialog_btnclose";
		this.btnclose.href="javascript:void(0);";
	}

	if(option.iframe)
	{
		this.iframe=window.parent.document.getElementById("dialog_iframe");
	}
	else
	{
		this.iframe=window.parent.document.createElement("iframe");
		this.iframe.id="dialog_iframe"
		this.iframe.frameBorder=0;
	}
	this.title.innerText=option.title;
	//this.html="";
	
	var src=location.pathname;
	src=src.toLowerCase().replace("/editor.htm","").replace("/editor."+$config.isapi,"");

	if(!this.StyleSheet)
	{	
		this.StyleSheet=window.parent.document.createElement("link");
		this.StyleSheet.rel="stylesheet";
		this.StyleSheet.type="text/css";
		//this.StyleSheet.href=src+"/skins/"+$arg.skin+"/dialog.css";
		this.StyleSheet.href=src+"/skins/dialog.css";
		window.parent.document.getElementsByTagName("head")[0].appendChild(this.StyleSheet);
	}
	window.parent.document.body.appendChild(this.masker);
	window.parent.document.body.appendChild(this.box);
	this.box.appendChild(this.title);
	this.box.appendChild(this.iframe);
	this.title.appendChild(this.btnclose);
	
	if(window.parent.document.documentElement.scrollHeight>0)
		this.masker.style.height=window.parent.document.documentElement.scrollHeight+"px";
	else
		this.masker.style.height="100%";
	this.box.style.width=option.width+"px";
	this.box.style.height=option.height+"px";

	if(option.url)
	{
		this.iframe.style.display="";
		this.iframe.style.height=this.box.clientHeight+this.title.clientHeight+"px";
		this.iframe.contentWindow.document.location=option.url;
	}
	else
	{
		this.iframe.style.display="none";
	}
	this.center();
}

__dialog.prototype.center=function()
{
	var w,h,p,t;
	if (window.parent.document.documentElement.clientWidth>0)
	{
		w=window.parent.document.documentElement.clientWidth;
		l=window.parent.document.documentElement.scrollLeft；
		h=window.parent.document.documentElement.clientHeight;
		t=window.parent.document.documentElement.scrollTop;
	}
	else
	{
		w=window.parent.document.body.clientWidth;
		l=window.parent.document.body.scrollLeft;
		h=window.parent.document.body.clientHeight;
		t=window.parent.document.body.scrollTop;
	}
	
	this.box.style.left=(w-this.box.clientWidth)/2+l+"px";
	this.box.style.top=(h-this.box.clientHeight)/2+t+"px";
}

__dialog.prototype.close=function()
{
	this.masker.style.display="none";
}

var $dialog=new __dialog();